package com.qingcheng.consumer;

import com.alibaba.fastjson.JSON;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;

import java.util.Map;

public class SmsMessageConsumer implements MessageListener {

    @Value("${smsCode}")
    private String smsCode;

    @Value("${param}")
    private String param;

    @Autowired
    private SmsUtil smsUtil;

    @Override
    public void onMessage(Message message) {

        String jsonString = new String(message.getBody());
        Map<String,String> map = JSON.parseObject(jsonString, Map.class);
        String phone = map.get("phone");//手机号
        String code = map.get("code");//验证码

        System.out.println("手机号:"+phone+" 验证码:"+code);

        //使用阿里云短信服务发送短信
        smsUtil.sendSms(phone,smsCode,param.replace("[value]",code));
    }
}
